<template>
  <div class="home-wrapper">
    <div class="filters-wrapper tuandui_wrap" v-loading="fullscreenLoading">
      <el-tabs v-model="activeName">
        <el-tab-pane label="人员管理" name="first">
          <div class="cus-but">
            <el-button
              type="primary"
              size="mini"
              :disabled="isDisabled('adduser')"
              @click="addUserClick"
              >新建人员</el-button
            >
          </div>
          <el-dialog
            title="员工管理"
            :visible.sync="addstaff"
            :close-on-click-modal="false"
            width="30%"
            center
          >
            <el-row type="flex" align="middle" justify="center">
              <el-form
                label-width="100px"
                :model="addUserForm"
                :rules="addUserRules"
                ref="addUserForm"
                style="width: 85%"
              >
                <el-form-item class="is-required" label="姓名：" prop="name">
                  <el-input
                    v-model="addUserForm.name"
                    placeholder="请输入员工姓名"
                    size="small"
                  />
                </el-form-item>
                <el-form-item class="is-required" label="邮箱：" prop="account">
                  <el-input
                    v-model="addUserForm.account"
                    :disabled="addUserForm.id > 0"
                    placeholder="用于登录账号使用"
                    size="small"
                  />
                </el-form-item>
                <el-form-item
                  class="is-required"
                  label="登录密码："
                  prop="password"
                >
                  <el-input
                    v-model="addUserForm.password"
                    placeholder="请输入员工登录密码"
                    show-password
                    size="small"
                  />
                </el-form-item>
                <el-form-item
                  class="is-required"
                  label="确认密码："
                  prop="password2"
                >
                  <el-input
                    v-model="addUserForm.password2"
                    placeholder="请再次输入员工密码"
                    show-password
                    size="small"
                  />
                </el-form-item>
                <el-form-item
                  class="is-required"
                  label="所属部门："
                  prop="id_depart"
                >
                  <el-select
                    v-model="addUserForm.id_depart"
                    filterable
                    placeholder="选择部门"
                    size="small"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in owndepartlist"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                    <!-- <el-option label="运营部1" value="1"></el-option> -->
                    <!-- <el-option label="运营部12" value="2"></el-option> -->
                  </el-select>
                </el-form-item>
                <el-form-item class="is-required" label="角色：" prop="id_role">
                  <el-select
                    v-model="addUserForm.id_role"
                    filterable
                    placeholder="选择角色"
                    size="small"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in ownroles"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                    <!-- <el-option label="普通员工" value="1"></el-option> -->
                    <!-- <el-option label="负责人" value="2"></el-option>
                                        <el-option label="管理员" value="2"></el-option> -->
                  </el-select>
                </el-form-item>
              </el-form>
            </el-row>
            <el-row type="flex" align="middle" justify="center">
              <el-button size="small" @click="cancelAddUser">取 消</el-button>
              <el-button
                size="small"
                type="primary"
                @click="addUserPost"
                v-loading.fullscreen.lock="fullscreenLoading"
                >确定</el-button
              >
            </el-row>
          </el-dialog>
          <div class="form-wrapper" style="width: 300px">
            <el-input
              maxlength="20"
              placeholder="请输入姓名搜索"
              size="small"
              v-model="searchUser"
              @keyup.enter.native="searchUserClick"
            >
              <el-button
                slot="append"
                @click="searchUserClick"
                icon="el-icon-search"
              ></el-button>
            </el-input>
          </div>
          <el-table
            :data="userlist"
            border
            :header-cell-style="{
              'text-align': 'center',
              background: '#f7f7f7',
              color: '#666',
            }"
            style="width: 100%"
          >
          <template slot="empty" style="text-align: left">
        <el-empty description="暂无数据" />
      </template>
            <el-table-column prop="name" label="姓名" align="center">
            </el-table-column>
            <el-table-column prop="depart" label="部门" align="center">
            </el-table-column>
            <el-table-column prop="role" label="角色" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-switch
                  v-if="scope.row.is_update == 1"
                  v-model="scope.row.status"
                  :active-value="0"
                  :inactive-value="1"
                  active-text="停用账户"
                  @change="changeStatus(scope.row)"
                ></el-switch>
                <el-button
                  v-if="scope.row.is_update == 1"
                  style="margin-left: 10px"
                  size="mini"
                  type="primary"
                  @click="modifyUser(scope.$index, scope.row)"
                  >修改</el-button
                >
                <el-button
                  v-if="scope.row.is_delete == 1"
                  style="margin-left: 10px"
                  size="mini"
                  type="danger"
                  @click="delUser(scope.$index, scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <el-row type="flex" justify="end" style="margin-top: 20px">
            <el-pagination
              background
              layout="prev, pager, next"
              :current-page.sync="curPage"
              :total="userTotal"
              :page-size="pageSize"
              @current-change="handleCurrentChange('user', $event)"
            >
            </el-pagination>
          </el-row>
        </el-tab-pane>
        <!-- 分割线 -->
        <el-tab-pane label="部门管理" name="second">
          <div class="cus-but">
            <el-button
              type="primary"
              size="mini"
              :disabled="isDisabled('adddepart')"
              @click="addDepartShow"
              >新建部门</el-button
            >
            <el-dialog
              title="部门管理"
              :visible.sync="adddepart"
              :close-on-click-modal="false"
              width="30%"
              center
            >
              <el-row type="flex" align="middle" justify="center">
                <el-form
                  label-width="100px"
                  :model="addDepartForm"
                  :rules="addDepartRules"
                  ref="addDepartForm"
                  style="width: 85%"
                >
                  <el-form-item
                    class="is-required"
                    label="部门名称"
                    prop="name"
                  >
                    <el-input
                      v-model="addDepartForm.name"
                      placeholder="请输入部门名称"
                      size="small"
                    />
                  </el-form-item>
                  <el-form-item
                    class="is-required"
                    label="负责人："
                    prop="id_admin"
                  >
                    <el-select
                      v-model="addDepartForm.id_admin"
                      filterable
                      placeholder="选择人员"
                      size="small"
                      style="width: 100%"
                      remote
                      :remote-method="getUserList"
                      :loading="loading"
                    >
                      <el-option
                        v-for="item in departUsers"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      ></el-option>
                      <!-- <el-option label="李四" value="2"></el-option> -->
                    </el-select>
                  </el-form-item>
                </el-form>
              </el-row>
              <el-row type="flex" align="middle" justify="center">
                <el-button size="small" @click="cancelAddDepart"
                  >取 消</el-button
                >
                <el-button
                  size="small"
                  type="primary"
                  @click="addDepartPost"
                  v-loading.fullscreen.lock="fullscreenLoading"
                  >确定</el-button
                >
              </el-row>
            </el-dialog>
          </div>
          <el-table
            :data="departlist"
            border
            :header-cell-style="{
              'text-align': 'center',
              background: '#f7f7f7',
              color: '#666',
            }"
            style="width: 100%"
          >
            <el-table-column prop="name" label="部门" align="center">
            </el-table-column>
            <el-table-column prop="admin" label="负责人" align="center">
            </el-table-column>
            <el-table-column prop="status" label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.is_update == 1"
                  style="margin-left: 10px"
                  size="mini"
                  type="primary"
                  @click="modifyDepart(scope.$index, scope.row)"
                  >修改</el-button
                >
                <el-button
                  v-if="scope.row.is_delete == 1"
                  style="margin-left: 10px"
                  size="mini"
                  type="danger"
                  @click="delDepart(scope.$index, scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <!-- 分割线 -->
        <el-tab-pane label="人员目标" name="third">
          <div class="cus-but">
            <el-button
              @click="projectDataSearchClick({ page: 1, export: 1 })"
              size="small"
              style="width: 80px"
              >导出数据</el-button
            >
          </div>
          <el-row type="flex" align="middle">
            <div class="form-wrapper">
              <span class="filter-label">时间：</span>
              <el-date-picker
                v-model="mbtime"
                @change="changeDate"
                type="date"
                size="small"
                placeholder="选择日期"
                style="width: 160px"
                value-format="yyyy-MM-dd"
                :clearable="false"
              >
              </el-date-picker>
            </div>
            <div class="form-wrapper">
              <span class="filter-label">部门：</span>
              <el-select
                v-model="departmentid"
                placeholder="请选择"
                size="small"
                class="select-wrapper"
                filterable
              >
                <el-option
                  v-for="item in userProjectDepartList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </div>
            <div class="form-wrapper" style="width: 260px">
              <el-input
                placeholder="请输入内容"
                size="small"
                v-model="person_search"
                class="input-with-select"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="loadUserProjectList({})"
                ></el-button>
              </el-input>
            </div>
          </el-row>
          <el-table
            :data="userProjectList"
            border
            :header-cell-style="{
              'text-align': 'center',
              background: '#f7f7f7',
              color: '#666',
            }"
            style="width: 100%; margin-top: 10px"
            ref="multipleTable"
          >
            <el-table-column prop="user" label="人员" align="center">
            </el-table-column>
            <el-table-column prop="role_name" label="角色" align="center">
            </el-table-column>
            <el-table-column label="本月目标" align="center" width="300">
              <template slot-scope="scope">
                <el-row
                  v-if="scope.row.is_update == 1"
                  type="flex"
                  align="middle"
                  justify="center"
                >
                  <el-input
                    v-model.number="scope.row.target"
                    size="small"
                    placeholder="输入项目目标"
                    style="width: 130px"
                  />
                  <el-button
                    style="margin-left: 5px"
                    size="mini"
                    @click="saveTarget('', scope.$index, scope.row)"
                    >确认</el-button
                  >
                </el-row>
                <el-row
                  v-if="scope.row.is_update != 1"
                  type="flex"
                  align="middle"
                  justify="center"
                >
                  {{ scope.row.target }}
                </el-row>
                <!-- <el-row v-if="scope.row.is_update == 1" type="flex" align="middle" justify="center">
                                    个人：<el-input v-model.number="scope.row.target_own" size="small" placeholder="输入个人目标"
                                        style="width:130px" />
                                    <el-button style="margin-left: 5px;" size="mini" @click="saveTarget('_own', scope.$index, scope.row)">确认</el-button>
                                </el-row> -->
              </template>
            </el-table-column>
            <el-table-column prop="total_expend" label="总消耗" align="center">
            </el-table-column>
            <el-table-column prop="day_expend" label="日均消耗" align="center">
            </el-table-column>
            <el-table-column prop="finish" label="完成进度" align="center">
            </el-table-column>
            <el-table-column
              prop="day_difference"
              label="日均差额"
              align="center"
            >
            </el-table-column>
            <!-- <el-table-column type="selection" width="55" align="center">
            </el-table-column> -->
          </el-table>
          <el-row type="flex" justify="end" style="margin-top: 20px">
            <el-pagination
              background
              layout="prev, pager, next"
              :current-page.sync="curPageProject"
              :total="userProjectTotal"
              :page-size="pageSize"
              @current-change="handleCurrentChange('userProject', $event)"
            >
            </el-pagination>
          </el-row>
          <!-- <el-row type="flex" justify="end" style="margin-top: 20px">
            <el-button size="small" @click="toggleSelection(mubiaodata)">反选</el-button>
            <el-button size="small" type="primary">催办</el-button>
          </el-row> -->
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<style>
.tuandui_wrap {
  padding-top: 10px;
}

.tuandui_wrap .el-tabs__content {
  overflow: initial;
  position: relative;
}

.tuandui_wrap .el-tabs__nav-wrap::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  background-color: #e4e7ed;
  z-index: 1;
}

.tuandui_wrap .cus-but {
  position: absolute;
  right: 0;
  top: -53px;
}

.tuandui_wrap .mtable-p {
  margin: 3px 0;
}
</style>
<script>
import { pageParams, checkRole, parseTime } from "@/settings";
const PASSWORD_MARK = "***************";
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else if (value.length < 6 || value.length > 20) {
        callback(new Error("长度在 6 到 20 个字符"));
      } else {
        callback();
      }
    };
    var validateMail = (rule, value, callback) => {
      /*eslint no-useless-escape: "error"*/
      var myreg = /^([a-zA-Z0-9]+[_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
      if (!myreg.test(value)) {
        callback(new Error("邮箱格式不正确"));
      }
      callback();
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.addUserForm.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      fullscreenLoading: false,
      loading: false,
      activeName: "first",
      searchUser: "",
      adddepart: false,
      pageSize: pageParams.pageSize,
      curPageProject: 1,
      curPage: 1,
      roles: [],
      ownroles: [],
      userlist: [],
      userTotal: 0,
      departlist: [],
      owndepartlist: [],
      departUsers: [],
      departmentid: "",
      person_search: "",
      addUserForm: {
        id: 0,
        name: "",
        account: "",
        password: "",
        password2: "",
        id_depart: "",
        id_role: "",
      },
      data_wheres: {
        time: parseTime(new Date(), "{y}-{m}-{d}"),
      },
      addUserRules: {
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 2, max: 5, message: "长度在 2 到 5 个字符", trigger: "blur" },
        ],
        account: [
          { required: true, message: "请输入邮箱", trigger: "blur" },
          // { min: 10, max: 50, message: '长度在 10 到 50 个字符', trigger: 'blur' },
          { validator: validateMail, trigger: "blur" },
        ],
        password: [
          // { required: true, message: '请输入密码', trigger: 'blur' },
          // { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
          { validator: validatePass, trigger: "blur" },
        ],
        password2: [
          // { required: true, message: '请输入密码', trigger: 'blur' },
          // { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' },
          { validator: validatePass2, trigger: "blur" },
        ],
        id_depart: [
          { required: true, message: "请选择部门", trigger: "change" },
        ],
        id_role: [{ required: true, message: "请选择角色", trigger: "change" }],
      },
      addDepartForm: {
        id: 0,
        name: "",
        id_admin: "",
      },
      addDepartRules: {
        name: [
          { required: true, message: "请输入部门名", trigger: "blur" },
          {
            min: 2,
            max: 10,
            message: "长度在 2 到 10 个字符",
            trigger: "blur",
          },
        ],
        id_admin: [
          { required: true, message: "请选择部门负责人", trigger: "blur" },
        ],
      },
      userProjectDepartList: [],
      userProjectList: [],
      userProjectTotal: 0,
      mbtime: parseTime(new Date(), "{y}-{m}-{d}"),
      addstaff: false,
      // addreny: {
      //     name: '',
      //     email:'',
      //     mimaone: '',
      //     mimatwo: '',
      //     depart: '',
      //     role: ''
      // },
      multipleSelection: [],
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    loadData() {
      this.$axios
        .get("/user/roles")
        .then((e) => {
          // console.log('角色列表', e.data)
          this.roles = e.data;
          let id_role = checkRole(this.$store.state.user.id_role);
          if (id_role === 1) {
            this.ownroles = this.roles;
          } else if (id_role === 2) {
            this.ownroles = this.roles.filter((item) => {
              return item.id >= 3;
            });
          }
        })
        .catch(() => {});
      this.$axios
        .get("/depart/list")
        .then((e) => {
          // console.log('部门列表', e.data)
          let d = e.data.slice(0);
          d.splice(0, 0, {
            id: "",
            name: "全部",
          });
          this.userProjectDepartList = d;
          this.departlist = e.data;
          let id_role = checkRole(this.$store.state.user.id_role);
          if (id_role === 1) {
            this.owndepartlist = this.departlist;
          } else if (id_role === 2) {
            this.owndepartlist = this.departlist.filter((item) => {
              return item.id === this.$store.state.user.id_depart;
            });
          }
        })
        .catch(() => {});
      this.loadUserList({});
      this.loadUserProjectList({});
    },
    loadUserList(param, callback) {
      this.fullscreenLoading = true;
      param["number"] = this.pageSize;
      if (!param["name"]) {
        param["name"] = this.searchUser;
      }
      if (!param["page"]) {
        param["page"] = 1;
      }
      if (!callback) {
        this.curPage = param["page"];
      }
      this.$axios
        .get("/user/list", param)
        .then((e) => {
          this.fullscreenLoading = false;
          // console.log('人员列表', e.data)
          if (callback) {
            callback(e.data);
          } else {
            this.userlist = e.data;
            this.userTotal = e.total;
            this.departUsers = e.data;
          }
        })
        .catch(() => {});
    },
    loadUserProjectList(param) {
      param["number"] = this.pageSize;
      param["time"] = this.mbtime;
      param["keyword"] = this.person_search;
      param["departid"] = this.departmentid;
      this.fullscreenLoading = true;
      if (!param["page"]) {
        param["page"] = 1;
      }
      this.curPageProject = param["page"];
      // console.log(param)
      this.$axios
        .get("/user/project/list", param)
        .then((e) => {
          this.fullscreenLoading = false;
          console.log("目标列表", e.data);
          this.userProjectList = e.data;
          this.userProjectTotal = e.total;
        })
        .catch(() => {});
    },
    loadDepartList(param) {
      this.fullscreenLoading = true;
      this.$axios
        .get("/depart/list", param)
        .then((e) => {
          this.fullscreenLoading = false;
          // console.log('部门列表', e.data)
          this.departlist = e.data;
        })
        .catch(() => {});
    },
    isDisabled(t) {
      // console.log('isDisabled', t, this.$store.state.user)
      let id_role = checkRole(this.$store.state.user.id_role);
      if (t == "adduser" && id_role && id_role > 2) {
        return true;
      } else if (t == "adddepart" && id_role && id_role > 1) {
        return true;
      }
      return false;
    },
    addUserPost() {
      // console.log('this.addUserForm', this.addUserForm)
      this.$refs["addUserForm"].validate((valid) => {
        if (valid) {
          this.addstaff = false;
          this.fullscreenLoading = true;
          let param = JSON.parse(JSON.stringify(this.addUserForm));
          if (param["password"] == PASSWORD_MARK) {
            param["password"] = "";
            param["password2"] = "";
          }
          // console.log('this.addUserForm', this.addUserForm)
          this.$axios
            .post("/user/add", param)
            .then((e) => {
              // this.$refs['addUserForm'].resetFields()
              this.fullscreenLoading = false;
              this.$message.success(e.msg ? e.msg : "操作成功");
              // console.log('添加结果', e)
              this.loadUserList({});
            })
            .catch(() => {
              this.fullscreenLoading = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleCurrentChange(t, val) {
      // console.log(t, val)
      if (t == "user") {
        this.loadUserList({ page: val });
      } else if (t == "userProject") {
        this.loadUserProjectList({ page: val });
      }
    },
    searchUserClick() {
      this.loadUserList({});
    },
    addUserClick() {
      for (let key in this.addUserForm) {
        this.addUserForm[key] = "";
      }
      this.addstaff = true;
    },
    cancelAddUser() {
      this.addstaff = false;
      this.$refs["addUserForm"].resetFields();
    },
    modifyUser(index, item) {
      item.password = PASSWORD_MARK;
      item.password2 = PASSWORD_MARK;
      // this.addUserForm = item
      for (let key in this.addUserForm) {
        this.addUserForm[key] = item[key] ? item[key] : "";
      }
      this.addstaff = true;
    },

    projectDataSearchClick() {
      let tmp = JSON.parse(JSON.stringify(this.data_wheres));
      console.log(tmp);
      // if (param['export']) {
      location.href =
        "http://ad.adjdds.com/api/export/team/?json=" + JSON.stringify(tmp);
    },

    //   toggleSelection(rows) {
    //     if (rows) {
    //       rows.forEach(row => {
    //         this.$refs.multipleTable.toggleRowSelection(row)
    //       })
    //     } else {
    //       this.$refs.multipleTable.clearSelection()
    //     }
    //   },
    delUser(index, item) {
      this.$confirm(
        "此操作将删除该人员[" + item.name + "], 是否继续?",
        "提示",
        {
          confirmButtonText: "确定删除",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.fullscreenLoading = true;
          this.$axios
            .get("/user/del", { id: item.id })
            .then((e) => {
              this.fullscreenLoading = false;
              this.$message({
                type: "success",
                message: e.msg ? e.msg : "删除成功!",
              });
              this.loadUserList({});
            })
            .catch(() => {
              this.fullscreenLoading = false;
            });
        })
        .catch(() => {});
    },
    modifyDepart(index, item) {
      // console.log(item)
      this.addDepartForm.name = item.name;
      this.addDepartForm.id_admin = item.id_admin;
      this.addDepartForm.id = item.id;
      // this.addUserForm.password = '***************'
      this.adddepart = true;
    },
    //   toggleSelection(rows) {
    //     if (rows) {
    //       rows.forEach(row => {
    //         this.$refs.multipleTable.toggleRowSelection(row)
    //       })
    //     } else {
    //       this.$refs.multipleTable.clearSelection()
    //     }
    //   },
    delDepart(index, item) {
      // console.log(index, item)
      this.$confirm(
        "此操作将删除该部门[" + item.name + "], 是否继续?",
        "提示",
        {
          confirmButtonText: "确定删除",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.fullscreenLoading = true;
          this.$axios
            .get("/depart/del", { id: item.id })
            .then((e) => {
              // console.log(e)
              this.fullscreenLoading = false;
              this.$message({
                type: "success",
                message: e.msg ? e.msg : "删除成功!",
              });
              this.loadDepartList({});
            })
            .catch(() => {
              this.fullscreenLoading = false;
            });
        })
        .catch(() => {});
    },
    addDepartShow() {
      // this.$refs['addDepartForm'].resetFields()
      for (let key in this.addDepartForm) {
        this.addDepartForm[key] = "";
      }
      this.adddepart = true;
    },
    addDepartPost() {
      this.$refs["addDepartForm"].validate((valid) => {
        if (valid) {
          this.adddepart = false;
          this.fullscreenLoading = true;
          console.log("添加/修改部门", this.addDepartForm);
          this.$axios
            .post("/depart/add", this.addDepartForm)
            .then(() => {
              // this.$refs['addUserForm'].resetFields()
              this.fullscreenLoading = false;
              // console.log('添加结果', e)
              this.loadDepartList({});
            })
            .catch(() => {
              this.fullscreenLoading = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    cancelAddDepart() {
      this.adddepart = false;
      this.$refs["addDepartForm"].resetFields();
    },
    getUserList(query) {
      this.loadUserList({ name: query }, (ret) => {
        // console.log(ret)
        this.departUsers = ret;
      });
    },
    saveTarget(key, index, item) {
      this.fullscreenLoading = true;
      var data = { id: item.id, type: key, val: item["target" + key] };
      // console.log(key, index, item, data)
      this.$axios
        .post("/project/user/save", data)
        .then((e) => {
          // this.$refs['addUserForm'].resetFields()
          this.fullscreenLoading = false;
          this.$message({
            type: "success",
            message: e.msg ? e.msg : "保存成功!",
          });
          this.loadDepartList({});
        })
        .catch(() => {
          this.fullscreenLoading = false;
        });
    },
    changeStatus(row) {
      console.log(row);
      // let srcStatus = row.status
      let srcStatus = row.status == 0 ? 1 : 0;
      this.$axios
        .post("/user/status", { id: row.id, status: row.status })
        .then((e) => {
          row.status = e.data.new_status;
          this.$message.success(e.msg ? e.msg : "操作成功");
        })
        .catch(() => {
          row.status = srcStatus;
        });
    },
    changeDate() {
      this.userProjectList = [];
      this.userProjectTotal = 0;
      this.loadUserProjectList({});
    },
  },
};
</script>
